package com.joolun.mall.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.joolun.mall.domain.vo.ShopVO;
import com.joolun.mall.entity.DwsVipOrderStat;
import com.joolun.mall.mapper.DwsVipOrderStatMapper;
import com.joolun.mall.service.DwsVipOrderStatService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * 淘宝旺店通关联关系
 * 
 * @author www.joolun.com
 * @date 2025-05-20
 */
@Service
public class DwsVipOrderStatServiceImpl extends ServiceImpl<DwsVipOrderStatMapper, DwsVipOrderStat> implements DwsVipOrderStatService {
    @Autowired
    private DwsVipOrderStatMapper vipOrderStatMapper;

    @Override
    public List<ShopVO> shopList() {
        return vipOrderStatMapper.shopList();
    }

    @Override
    public Page<DwsVipOrderStat> page1(Page<DwsVipOrderStat> page, DwsVipOrderStat dto) {
        if(StringUtils.isNotBlank(dto.getOrderFiled())){
            dto.setOrderFiled(StringUtils.uncapitalize(dto.getOrderFiled()).replaceAll("([A-Z])", "_$1").toLowerCase());
        }
        return vipOrderStatMapper.page1(page, dto);
    }

    @Override
    public DwsVipOrderStat total(DwsVipOrderStat dto) {
        DwsVipOrderStat total = vipOrderStatMapper.total(dto);
        if(Objects.isNull(total)){
            total = new DwsVipOrderStat();
            total.setSaleAmt(BigDecimal.ZERO);
            total.setSaleQty(BigDecimal.ZERO);
            total.setRealAmt(BigDecimal.ZERO);
            total.setRealQty(BigDecimal.ZERO);
        }
        return total;
    }
}
